<html>
<head><meta charset="utf-8"><title>Fixing broken target==host cross compilation. · t-cargo · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/index.html">t-cargo</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html">Fixing broken target==host cross compilation.</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="232107991"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232107991" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Hilliard <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232107991">(Mar 27 2021 at 18:19)</a>:</h4>
<p>I'm trying to track down and fix a longstanding bug that seems to prevent cargo from successfully cross compiling for a x86_64 target from a x86_64 host, would anyone happen to know where/how cargo is determining if it needs to cross compile for the target vs native compile? Essentially the issue I'm running into seems to be that cargo is incorrectly attempting to cross compile a build script for the target which actually needs to be native compiled for the host.</p>



<a name="232111520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232111520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232111520">(Mar 27 2021 at 19:16)</a>:</h4>
<p>Cargo "cross-compiles" when you pass --target. Even if that target is the host target, it should build all build scripts, proc macros and their dependencies separately for the host and the target.</p>



<a name="232111546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232111546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232111546">(Mar 27 2021 at 19:16)</a>:</h4>
<p><span class="user-mention" data-user-id="399686">@James Hilliard</span> What is the exact issue?</p>



<a name="232111665"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232111665" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Hilliard <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232111665">(Mar 27 2021 at 19:19)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133247">bjorn3</span> <a href="#narrow/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E/near/232111546">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="399686">James Hilliard</span> What is the exact issue?</p>
</blockquote>
<p>Issue is that is linking the build scripts using the target linker instead of the host linker, which means the build scripts fail to run.</p>



<a name="232111877"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232111877" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232111877">(Mar 27 2021 at 19:21)</a>:</h4>
<p>How did you define the target linker?</p>



<a name="232111916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232111916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Hilliard <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232111916">(Mar 27 2021 at 19:22)</a>:</h4>
<p>For example I'm seeing this error:</p>
<div class="codehilite"><pre><span></span><code>/home/buildroot/buildroot/output/build/python-cryptography-3.4.6/src/rust/target/release/build/syn-a9e6d896813f574d/build-script-build: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.32&#39; not found (required by /home/buildroot/buildroot/output/build/python-cryptography-3.4.6/src/rust/target/release/build/syn-a9e6d896813f574d/build-script-build)
</code></pre></div>
<p>with this cargo config:</p>
<div class="codehilite"><pre><span></span><code>[target.x86_64-unknown-linux-gnu]
linker = &quot;x86_64-buildroot-linux-gnu-gcc&quot;
</code></pre></div>



<a name="232111969"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232111969" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Hilliard <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232111969">(Mar 27 2021 at 19:23)</a>:</h4>
<p>The error seems to indicate it's linking against the target glibc instead of the host glibc for the build scripts.</p>



<a name="232112155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232112155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232112155">(Mar 27 2021 at 19:26)</a>:</h4>
<p>Yeah it is probably using the specified linker for all x86_64-unknown-linux-gnu targets. Why do you need a different linker for host and target? The host has an older glibc version which means that a program linked against the host glibc would also run on the target.</p>



<a name="232112407"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232112407" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Hilliard <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232112407">(Mar 27 2021 at 19:31)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133247">bjorn3</span> <a href="#narrow/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E/near/232112155">said</a>:</p>
<blockquote>
<p>Yeah it is probably using the specified linker for all x86_64-unknown-linux-gnu targets. Why do you need a different linker for host and target? The host has an older glibc version which means that a program linked against the host glibc would also run on the target.</p>
</blockquote>
<p>Because I'm cross compiling the binary for a target system, target libraries here should never be linked against host libraries like that as doing so would be basically guaranteed to break in subtle ways, the buildroot build system I'm using can be run on many different hosts so we can't rely on the host having a target compatible glibc at all. So we need a way to ensure build script never use the target linker.</p>



<a name="232114999"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232114999" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Hilliard <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232114999">(Mar 27 2021 at 20:08)</a>:</h4>
<p>It's very strange that the target linker config affects which host linker used at all, anyone know why it would be doing that? I would normally expect there to be a fully separate configuration for the host linker.</p>



<a name="232327683"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232327683" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Hilliard <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232327683">(Mar 29 2021 at 20:06)</a>:</h4>
<p>anyone have any idea where I should be looking in the cargo codebase to try and fix this issue?</p>



<a name="232328459"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232328459" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232328459">(Mar 29 2021 at 20:11)</a>:</h4>
<p>Unfortunately this isn't really a bug in Cargo, it's moreso just how it works. This "feature" is a known deficiency though for a whole host of reasons. Another common example is <code>RUSTFLAGS</code> without <code>--target</code> where it applies to proc macros as well. Most of the code for managing this is in <code>src/cargo/core/compiler</code> and if you poke around there you'll see <code>CompileKind::{Host, Target}</code> which may be at least a starting point for playing around with things.</p>
<p>Landing things in this area may be somewhat difficult though due to the fact that any changes are breaking changes for Cargo</p>



<a name="232331018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232331018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232331018">(Mar 29 2021 at 20:32)</a>:</h4>
<p><span class="user-mention" data-user-id="116015">@Alex Crichton</span> In theory, could this kind of thing be changed over an edition boundary, with enough care?</p>



<a name="232331099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232331099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232331099">(Mar 29 2021 at 20:32)</a>:</h4>
<p>For instance, making Cargo <em>always</em> separate target and host, even if they're the same, and never have a special case for "not cross compiling"?</p>



<a name="232345594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232345594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232345594">(Mar 29 2021 at 22:26)</a>:</h4>
<p>Perhaps? This doesn't feel like something that should be edition related though and something where if we changed it we should roll out on a normal cadence</p>



<a name="232375354"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232375354" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232375354">(Mar 30 2021 at 05:16)</a>:</h4>
<p>I'm not sure why it wouldn't be edition related, if it's a backwards compatibility issue.</p>



<a name="232375373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232375373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232375373">(Mar 30 2021 at 05:17)</a>:</h4>
<p>What would be the alternative to avoid breaking existing users?</p>



<a name="232381211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232381211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232381211">(Mar 30 2021 at 06:46)</a>:</h4>
<p>This seems similar to e.g. <code>resolver = "2"</code> changes from compatibility point of view.</p>



<a name="232439081"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232439081" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232439081">(Mar 30 2021 at 14:53)</a>:</h4>
<p>Right, exactly.</p>



<a name="232628561"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232628561" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Hilliard <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232628561">(Mar 31 2021 at 17:06)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116015">Alex Crichton</span> <a href="#narrow/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E/near/232328459">said</a>:</p>
<blockquote>
<p>Unfortunately this isn't really a bug in Cargo, it's moreso just how it works. This "feature" is a known deficiency though for a whole host of reasons. Another common example is <code>RUSTFLAGS</code> without <code>--target</code> where it applies to proc macros as well. Most of the code for managing this is in <code>src/cargo/core/compiler</code> and if you poke around there you'll see <code>CompileKind::{Host, Target}</code> which may be at least a starting point for playing around with things.</p>
<p>Landing things in this area may be somewhat difficult though due to the fact that any changes are breaking changes for Cargo</p>
</blockquote>
<p>Hmm, should the broken target==host logic all be in the same place or is going to need changes in a number of places to fix/override?</p>



<a name="232628799"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232628799" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Hilliard <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232628799">(Mar 31 2021 at 17:08)</a>:</h4>
<p>Maybe something that would make <a href="https://github.com/rust-lang/cargo/blob/58a961314437258065e23cb6316dfc121d96fb71/src/cargo/core/compiler/compile_kind.rs#L31-L33">https://github.com/rust-lang/cargo/blob/58a961314437258065e23cb6316dfc121d96fb71/src/cargo/core/compiler/compile_kind.rs#L31-L33</a> always false?</p>



<a name="232629279"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232629279" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232629279">(Mar 31 2021 at 17:11)</a>:</h4>
<p><span class="user-mention silent" data-user-id="399686">James Hilliard</span> <a href="#narrow/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E/near/232628799">said</a>:</p>
<blockquote>
<p>Maybe something that would make <a href="https://github.com/rust-lang/cargo/blob/58a961314437258065e23cb6316dfc121d96fb71/src/cargo/core/compiler/compile_kind.rs#L31-L33">https://github.com/rust-lang/cargo/blob/58a961314437258065e23cb6316dfc121d96fb71/src/cargo/core/compiler/compile_kind.rs#L31-L33</a> always false?</p>
</blockquote>
<p>No, that needs to be true for build scripts, proc macros and their dependencies as those must always be built for the host.</p>



<a name="232629632"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232629632" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Hilliard <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232629632">(Mar 31 2021 at 17:14)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E/near/232331099">said</a>:</p>
<blockquote>
<p>For instance, making Cargo <em>always</em> separate target and host, even if they're the same, and never have a special case for "not cross compiling"?</p>
</blockquote>
<p>Well in our cargo config we have <code>[target.x86_64-unknown-linux-gnu]</code> which seems to apply to both host and targets even though one would assume it only applies to the target as the name would suggest, so instead we should maybe add a <code>[host.x86_64-unknown-linux-gnu]</code> for setting host settings and a <code>[x86_64-unknown-linux-gnu]</code> to set both target and host along with changing <code>[target.x86_64-unknown-linux-gnu]</code> to only configure the target?</p>



<a name="232630225"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232630225" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Hilliard <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232630225">(Mar 31 2021 at 17:17)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133247">bjorn3</span> <a href="#narrow/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E/near/232629279">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="399686">James Hilliard</span> <a href="#narrow/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E/near/232628799">said</a>:</p>
<blockquote>
<p>Maybe something that would make <a href="https://github.com/rust-lang/cargo/blob/58a961314437258065e23cb6316dfc121d96fb71/src/cargo/core/compiler/compile_kind.rs#L31-L33">https://github.com/rust-lang/cargo/blob/58a961314437258065e23cb6316dfc121d96fb71/src/cargo/core/compiler/compile_kind.rs#L31-L33</a> always false?</p>
</blockquote>
<p>No, that needs to be true for build scripts, proc macros and their dependencies as those must always be built for the host.</p>
</blockquote>
<p>Oh, so that's for determining if what's being compiled needs to run on the host or the target? Any idea where the code that is applying the target linker settings to the host settings would be?</p>



<a name="232631063"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232631063" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232631063">(Mar 31 2021 at 17:22)</a>:</h4>
<p><a href="https://github.com/rust-lang/cargo/blob/58a961314437258065e23cb6316dfc121d96fb71/src/cargo/core/compiler/mod.rs#L906">https://github.com/rust-lang/cargo/blob/58a961314437258065e23cb6316dfc121d96fb71/src/cargo/core/compiler/mod.rs#L906</a> I think which calls <a href="https://github.com/rust-lang/cargo/blob/58a961314437258065e23cb6316dfc121d96fb71/src/cargo/core/compiler/build_context/mod.rs#L91">https://github.com/rust-lang/cargo/blob/58a961314437258065e23cb6316dfc121d96fb71/src/cargo/core/compiler/build_context/mod.rs#L91</a> which I think gets the data from <a href="https://github.com/rust-lang/cargo/blob/58a961314437258065e23cb6316dfc121d96fb71/src/cargo/core/compiler/build_context/target_info.rs#L685">https://github.com/rust-lang/cargo/blob/58a961314437258065e23cb6316dfc121d96fb71/src/cargo/core/compiler/build_context/target_info.rs#L685</a> for the target and <a href="https://github.com/rust-lang/cargo/blob/58a961314437258065e23cb6316dfc121d96fb71/src/cargo/core/compiler/build_context/target_info.rs#L679">https://github.com/rust-lang/cargo/blob/58a961314437258065e23cb6316dfc121d96fb71/src/cargo/core/compiler/build_context/target_info.rs#L679</a> for the host.</p>



<a name="232638201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232638201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Hilliard <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232638201">(Mar 31 2021 at 18:07)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133247">bjorn3</span> <a href="#narrow/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E/near/232631063">said</a>:</p>
<blockquote>
<p><a href="https://github.com/rust-lang/cargo/blob/58a961314437258065e23cb6316dfc121d96fb71/src/cargo/core/compiler/mod.rs#L906">https://github.com/rust-lang/cargo/blob/58a961314437258065e23cb6316dfc121d96fb71/src/cargo/core/compiler/mod.rs#L906</a> I think which calls <a href="https://github.com/rust-lang/cargo/blob/58a961314437258065e23cb6316dfc121d96fb71/src/cargo/core/compiler/build_context/mod.rs#L91">https://github.com/rust-lang/cargo/blob/58a961314437258065e23cb6316dfc121d96fb71/src/cargo/core/compiler/build_context/mod.rs#L91</a> which I think gets the data from <a href="https://github.com/rust-lang/cargo/blob/58a961314437258065e23cb6316dfc121d96fb71/src/cargo/core/compiler/build_context/target_info.rs#L685">https://github.com/rust-lang/cargo/blob/58a961314437258065e23cb6316dfc121d96fb71/src/cargo/core/compiler/build_context/target_info.rs#L685</a> for the target and <a href="https://github.com/rust-lang/cargo/blob/58a961314437258065e23cb6316dfc121d96fb71/src/cargo/core/compiler/build_context/target_info.rs#L679">https://github.com/rust-lang/cargo/blob/58a961314437258065e23cb6316dfc121d96fb71/src/cargo/core/compiler/build_context/target_info.rs#L679</a> for the host.</p>
</blockquote>
<p>ah, thanks, so if I'm reading this right what we need to do is change <code>let host_config = config.target_cfg_triple(&amp;rustc.host)?;</code> to a <code>let host_config = config.host_cfg_triple(&amp;rustc.host)?;</code> or something like that and have it not read from the target configs but only host configs</p>



<a name="232643918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232643918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232643918">(Mar 31 2021 at 18:44)</a>:</h4>
<p>That and ensure that host and target dependencies. Currently the <code>host_config</code> is always used when not passing <code>--target</code>. Changing this is a breaking change.</p>



<a name="232644613"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232644613" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Hilliard <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232644613">(Mar 31 2021 at 18:49)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133247">bjorn3</span> <a href="#narrow/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E/near/232643918">said</a>:</p>
<blockquote>
<p>That and ensure that host and target dependencies. Currently the <code>host_config</code> is always used when not passing <code>--target</code>. Changing this is a breaking change.</p>
</blockquote>
<p>How is that an issue? When cross compiling we always need to pass a <code>--target</code> right?</p>



<a name="232644896"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232644896" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232644896">(Mar 31 2021 at 18:51)</a>:</h4>
<p>But when you are not cross-compiling, this would make <code>[target.x86_64-unknown-linux-gnu]</code> not work anymore.</p>



<a name="232644952"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232644952" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232644952">(Mar 31 2021 at 18:51)</a>:</h4>
<p>When not cross-compiling the "target" is the host, so this table should apply.</p>



<a name="232648838"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232648838" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232648838">(Mar 31 2021 at 19:17)</a>:</h4>
<p>another table such as <code>[host.*]</code> is necessary?</p>



<a name="232651240"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232651240" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Hilliard <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232651240">(Mar 31 2021 at 19:32)</a>:</h4>
<p><span class="user-mention silent" data-user-id="123586">nagisa</span> <a href="#narrow/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E/near/232648838">said</a>:</p>
<blockquote>
<p>another table such as <code>[host.*]</code> is necessary?</p>
</blockquote>
<p>I think so.</p>



<a name="232653668"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232653668" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232653668">(Mar 31 2021 at 19:47)</a>:</h4>
<p>I'm in agreement with the comment that this can be a choice in behaviour with a flag in <code>.cargo/config</code> or similar.</p>



<a name="232653718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232653718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232653718">(Mar 31 2021 at 19:47)</a>:</h4>
<p>Its going to be super hard to discover naturally, though.</p>



<a name="232654161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232654161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232654161">(Mar 31 2021 at 19:50)</a>:</h4>
<p>if you make this a toggle in .cargo/config, could you also add a way to enable it from the command line? Passing host flags to the target would be super helpful for <a href="https://github.com/rust-lang/cargo/issues/7677">https://github.com/rust-lang/cargo/issues/7677</a> and <a href="https://github.com/rust-lang/rust/pull/83433">https://github.com/rust-lang/rust/pull/83433</a>.</p>



<a name="232654433"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232654433" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232654433">(Mar 31 2021 at 19:51)</a>:</h4>
<p>for <a href="http://docs.rs">docs.rs</a> especially we don't <em>control</em> .cargo/config and can't write to it</p>



<a name="232658057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232658057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Hilliard <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232658057">(Mar 31 2021 at 20:16)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133247">bjorn3</span> <a href="#narrow/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E/near/232644952">said</a>:</p>
<blockquote>
<p>When not cross-compiling the "target" is the host, so this table should apply.</p>
</blockquote>
<p>How do I check if a <code>--target</code> was passed to cargo?</p>



<a name="232665896"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232665896" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Hilliard <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232665896">(Mar 31 2021 at 21:12)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E/near/232654161">said</a>:</p>
<blockquote>
<p>if you make this a toggle in .cargo/config, could you also add a way to enable it from the command line? Passing host flags to the target would be super helpful for <a href="https://github.com/rust-lang/cargo/issues/7677">https://github.com/rust-lang/cargo/issues/7677</a> and <a href="https://github.com/rust-lang/rust/pull/83433">https://github.com/rust-lang/rust/pull/83433</a>.</p>
</blockquote>
<p>Well I'm trying to make it so that hosts and targets are configured independently from each other in the cargo config so I think that should also be workable.</p>



<a name="232865994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/232865994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Hilliard <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#232865994">(Apr 02 2021 at 06:31)</a>:</h4>
<p>Think I came up with a fix <a href="https://github.com/rust-lang/cargo/pull/9322">https://github.com/rust-lang/cargo/pull/9322</a>.</p>



<a name="239991546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/239991546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> James Hilliard <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#239991546">(May 24 2021 at 01:08)</a>:</h4>
<p>Is there anything else I should change or explain still with <a href="https://github.com/rust-lang/cargo/pull/9322">https://github.com/rust-lang/cargo/pull/9322</a> ? Unclear what if I should be doing something here or not still...</p>



<a name="240001494"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/240001494" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#240001494">(May 24 2021 at 04:03)</a>:</h4>
<p>I think the ball is in our court to review further.</p>



<a name="240001498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/Fixing%20broken%20target%3D%3Dhost%20cross%20compilation./near/240001498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/Fixing.20broken.20target.3D.3Dhost.20cross.20compilation.2E.html#240001498">(May 24 2021 at 04:04)</a>:</h4>
<p>I'll take a look soonish.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>